#include <bits/stdc++.h>
using namespace std;
/** 
 * 
 * 
1 2 3
4 5 6
7 8 0
1 1
2 2
2 3
7
*/
int main()
{
    int graph[4][4];
    int number[10];
    int s[25] = {0, 0, 0, 0, 0, 0, 10000, 36, 720, 360, 80, 252, 108, 72, 54, 180, 72, 180, 119, 36, 306, 1080, 144, 1800, 3600};
    memset(number, 0, sizeof(number));
    for (int i = 1; i < 4; i++)
    {
        for (int j = 1; j < 4; j++)
        {
            cin >> graph[i][j];
            number[graph[i][j]] = 1;
        }
    }
    // 找到缺的数字
    int lack;
    for (int i = 1; i < 10; i++)
    {
        if (number[i] == 0)
        {
            lack = i;
            break;
        }
    }
    for (int i = 1; i < 4; i++)
    {
        for (int j = 1; j < 4; j++)
        {
            if (graph[i][j] == 0)
            {
                graph[i][j] = lack;
            }
        }
    }
    // 输入三个坐标
    int pos[3][2];
    for (int i = 0; i < 3; i++)
    {
        for (int j = 0; j < 2; j++)
        {
            cin >> pos[i][j];
        }
        cout << graph[pos[i][0]][pos[i][1]] << endl;
    }
    int d;
    cin >> d;
    int sum = 0;
    if (d == 1)
    {
        for (int i = 1; i <= 3; ++i)
        {
            sum += graph[1][i];
        }
    }
    else if (d == 2)
    {
        for (int i = 1; i <= 3; ++i)
        {
            sum += graph[2][i];
        }
    }
    else if (d == 3)
    {
        for (int i = 1; i <= 3; ++i)
        {
            sum += graph[3][i];
        }
    }
    else if (d == 4)
    {
        for (int i = 1; i <= 3; ++i)
        {
            sum += graph[i][1];
        }
    }
    else if (d == 5)
    {
        for (int i = 1; i <= 3; ++i)
        {
            sum += graph[i][2];
        }
    }
    else if (d == 6)
    {
        for (int i = 1; i <= 3; ++i)
        {
            sum += graph[i][3];
        }
    }
    else if (d == 7)
    {
        for (int i = 1; i <= 3; ++i)
        {
            sum += graph[i][i];
        }
    }
    else if (d == 8)
    {
        for (int i = 1; i <= 3; ++i)
        {
            sum += graph[i][4 - i];
        }
    }
    cout << s[sum] << endl;
    return 0;
}